package pub.guoxin.oops.collector.client;


import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * Created by guoxin on 17-10-11.
 */
public final class TheMomentClient {

    static final int PORT = Integer.parseInt(System.getProperty("port", "49224"));

    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket();
        String strInfo = "112233445566A1000000856BCE4201000000313233343536000000000000BD00833F5839743F5C8F823F6666CA4166E6CF42E17A14AEC701AB40E61000000000000085EB51B81E178240860000000000000033734B4352B8CA4171BDC542D763D8438FC2C542EF313233343536000000000000BD00833F5839743F5C8F823F6666CA4166E6CF42E17A14AEC701AB40E61000000000000085EB51B81E178240860000000000000033734B4352B8CA4171BDC542D763D8438FC2C542EF";
        byte[] bytes = strInfo.getBytes();
        socket.send(new DatagramPacket(strInfo.getBytes(), strInfo.length(), InetAddress.getByName("127.0.0.1"), PORT));
        socket.send(new DatagramPacket(strInfo.getBytes(), strInfo.length(), InetAddress.getByName("120.27.19.106"), PORT));
        socket.close();
//        EventLoopGroup group = new NioEventLoopGroup();
//        try {
//            Bootstrap b = new Bootstrap();
//            b.group(group)
//                    .channel(NioDatagramChannel.class)
//                    .remoteAddress("127.0.0.1",PORT)
//                    .handler(new TheMomentClientHandler());
//
//            Channel ch = b.bind(0).sync().channel();
//            int id = 0x00000221;
//            // Broadcast the QOTM request to port 8080.
//            ch.writeAndFlush(new DatagramPacket(
//                    Unpooled.copiedBuffer("Hello server", CharsetUtil.UTF_8),
//                    SocketUtils.socketAddress("127.0.0.1", PORT))).sync();
//            // TheMomentClientHandler will close the DatagramChannel when a
//            // response is received.  If the channel is not closed within 5 seconds,
//            // print an error message and quit.
//            if (!ch.closeFuture().await(5000)) {
//                System.err.println("QOTM request timed out.");
//            }
//        } finally {
//            group.shutdownGracefully();
//        }
    }


}